class Solution
{
public:
    int maxScore(string s)
    {
        int oneCount = 0;
        for (int i = 1; i < s.size(); ++i)
        {
            if (s[i] == '1')
            {
                ++oneCount;
            }
        }
        int zeroCount = s[0] == '0';
        int score = oneCount + zeroCount;
        for (int i = 1; i < s.size() - 1; ++i)
        {
            if (s[i] == '0')
            {
                ++zeroCount;
            }
            else
            {
                --oneCount;
            }
            score = max(score, oneCount + zeroCount);
        }
        return score;
    }
};